﻿using DeZhen.CollaborationPlatform.IService.ApiManagement;
using DeZhen.CollaborationPlatform.Model.Common;
using DeZhen.CollaborationPlatform.Model.DTO.ApiManagement;
using Microsoft.AspNetCore.Mvc;

namespace DeZhen.CollaborationPlatform.WebApi.Controllers
{
    /// <summary>
    /// 接口管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ApiManagementController : ControllerBase
    {
        private readonly IApiManagementService _service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public ApiManagementController(IApiManagementService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取接口管理分页列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpGet(Name = "GetApiManagementPaged")]
        public async Task<PageResult<ApiManagementDTO>> GetApiManagementPagedAsync([FromQuery] QueryApiManagementPage param)
        {
            return await _service.GetListToPageAsync(param);
        }

        /// <summary>
        /// 获取接口管理列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpGet(Name = "GetApiManagementList")]
        public async Task<List<ApiManagementDTO>> GetApiManagementListAsync([FromQuery] QueryApiManagement param)
        {
            return await _service.GetListAsync(param);
        }

        /// <summary>
        /// 根据ID获取接口管理对象DTO
        /// </summary>
        /// <param name="id">接口管理ID</param>
        /// <returns></returns>
        [HttpGet(Name = "GetApiManagement")]
        public async Task<ApiManagementDTO> GetApiManagementAsync(long id)
        {
            return await _service.GetByIdAsync(id);
        }

        /// <summary>
        /// 新增接口管理
        /// </summary>
        /// <param name="input">接口管理Add对象</param>
        /// <returns></returns>
        [HttpPost(Name = "AddApiManagement")]
        public async Task<long> AddApiManagementAsync(ApiManagementAdd input)
        {
            return await _service.AddAsync(input);
        }

        /// <summary>
        /// 更新接口管理
        /// </summary>
        /// <param name="input">接口管理Edit对象</param>
        /// <returns></returns>
        [HttpPut(Name = "EditApiManagement")]
        public async Task<bool> EditApiManagementAsync(ApiManagementEdit input)
        {
            return await _service.UpdateAsync(input);
        }

        /// <summary>
        /// 删除接口管理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete(Name = "DeleteApiManagement")]
        public async Task DeleteApiManagementAsync(long id)
        {
            await _service.DeleteAsync(id);
        }
    }
}
